var storage = window.localStorage

layui.use(function () {
  var form = layui.form;
  var layer = layui.layer;
  // 提交事件
  form.on('submit(demo-login)', function (data) {

    var field = data.field; // 获取表单字段值
    var access = false;
    //检验账号
    for (username in storage) {
      if (username == field.username && field.password == JSON.parse(storage.getItem(username)).password) {
        access = true
        break
      }
    }
    setTimeout(() => {
      if (access) location.href = 'index.html?' + JSON.stringify({ username: username, code: 1 })//跳转主页
      else layer.alert('账号或密码错误')
    }, 1000);

    return false; // 阻止默认 form 跳转
  });
});